package com.example.studentdemo.mapper;

import com.example.studentdemo.entity.SubjectStudent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SubjectStudentMapper {
    /**
     * 查询所有 subject_student 记录
     */
    List<SubjectStudent> selectAll(SubjectStudent subjectStudent);

    /**
     * 插入一条 subject_student 记录
     */
    @Insert("insert into subject_student (subject_id, student_id) values (#{subjectId}, #{studentId})")
    void insert(SubjectStudent subjectStudent);

    /**
     * 根据课程ID查询学生
     */
    @Select("select * from subject_student where subject_id = #{subjectId}")
    List<SubjectStudent> selectBySubjectId(Integer subjectId);

    /**
     * 根据学生ID查询课程
     */
    @Select("select * from subject_student where student_id = #{studentId}")
    List<SubjectStudent> selectByStudentId(Integer studentId);

    /**
     * 根据课程ID和学生ID删除记录
     */
    @Delete("delete from subject_student where subject_id = #{subjectId} and student_id = #{studentId}")
    void deleteBySubjectIdAndStudentId(SubjectStudent subjectStudent);

    /**
     * 根据课程ID删除所有相关记录
     */
    @Delete("delete from subject_student where subject_id = #{subjectId}")
    void deleteBySubjectId(Integer subjectId);

    /**
     * 根据学生ID删除所有相关记录
     */
    @Delete("delete from subject_student where student_id = #{studentId}")
    void deleteByStudentId(Integer studentId);
}